#include"BlockQueue.hpp"
void* Consumer(void* args)
{
   auto bq = static_cast<BlockQueue<int>*>(args);
   int x;
   sleep(2);
   while(true)
   {
    //消费
     x = bq->pop();
     std::cout << "消费了一个数据: " << x << "此时还有: " << bq->size() << "个数据" << std::endl;
     sleep(3);
   } 
}

void* Producter(void* args)
{
    auto bq = static_cast<BlockQueue<int>*>(args);
    int data = 0;
    while(true)
    {
        //生产
        data++;
        bq->push(data);
        std::cout << "生产了一个数据: " << data << "此时还有: " << bq->size() << "个数据" << std::endl;
        sleep(2);
    }
}

int main()
{
    //可以传递对象
    BlockQueue<int>* bq = new BlockQueue<int>();
    pthread_t c,p;
    pthread_create(&c,nullptr,Consumer,(void*)bq);
    pthread_create(&p,nullptr,Producter,(void*)bq);
    pthread_join(c,nullptr);
    pthread_join(p,nullptr);

    delete bq;
    return 0;
}